package com.juneng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.R;
import com.juneng.utils.Func;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.juneng.entity.BookDiscount;
import com.juneng.dto.BookDiscountDto;
import com.juneng.dto.BookDiscountQueryDto;
import com.juneng.vo.BookDiscountVo;
import com.juneng.service.IBookDiscountService;

/**
 * 书籍折扣 控制器
 *  /bookDiscount/v1/list
 * @author zds
 * @since 2021-07-30
 */
@RestController
@AllArgsConstructor
@RequestMapping("bookDiscount")
@Api(tags = "书籍折扣相关接口")
public class BookDiscountController {

	private IBookDiscountService bookDiscountService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<BookDiscount> detail(Integer id) {
		BookDiscount detail = bookDiscountService.getById(id);
		return R.success(detail);
	}

	/**
	 * 分页 书籍折扣 <title>500 Internal Server Error</title>
	 */
	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入bookDiscount")
	public R<IPage<BookDiscountVo>> page(BookDiscountQueryDto dto) {
		IPage<BookDiscountVo> pages = bookDiscountService.page(dto);
		return R.success(pages);
	}
	/**
	 * 列表 书籍折扣 chunk-elementUI.9271279c.js:1 POST http://backstage.liuludushu.com/common/v1/uploadImage net::ERR_FAILED
	 */
	@GetMapping("/list")
	@ApiOperation(value = "不分页", notes = "传入bookDiscount")
	public R<List<BookDiscount>> list(BookDiscountQueryDto dto) {
		List<BookDiscount> list = bookDiscountService.list(dto);
		return R.success(list);
	}

	/**
	 * 新增 书籍折扣
	 */
	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入bookDiscount")
	public R save(@RequestBody BookDiscountDto dto) {
		return R.success(bookDiscountService.save(dto));
	}

	/**
	 * 修改 书籍折扣
	 */
	@PutMapping("/update")
	@ApiOperation(value = "修改", notes = "传入bookDiscount")
	public R update(@RequestBody BookDiscountDto dto) {
		return R.success(bookDiscountService.updateById(dto));
	}

	/**
	 * 删除 书籍折扣
	 */
	@DeleteMapping("/remove")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.success(bookDiscountService.deleteLogic(Func.toIntList(ids)));
	}
}
